package com.kookapi.enums;

import lombok.Getter;

/**
 * Http请求枚举，自定义在字典中
 */
@Getter
public enum HttpEnum {

    GET("0", "GET"),
    POST("1", "POST"),
    PUT("2", "PUT"),
    DELETE("3", "DELETE");

    public final String code;
    public final String method;

    HttpEnum(String code, String method) {
        this.code = code;
        this.method = method;
    }

    /**
     * 根据code返回对应的HttpEnum
     * @param code 编码
     * @return HttpEnum 对应的枚举值，找不到返回null
     */
    public static HttpEnum getByCode(String code) {
        for (HttpEnum httpEnum : HttpEnum.values()) {
            if (httpEnum.code.equals(code)) {
                return httpEnum;
            }
        }
        return null;
    }

    /**
     * 根据code返回对应的方法名
     * @param code 编码
     * @return method 对应的方法名，找不到返回null
     */
    public static String getMethodByCode(String code) {
        HttpEnum httpEnum = getByCode(code);
        return httpEnum != null ? httpEnum.method : null;
    }
}
